﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BOSS.Domain
{
    /// <summary>
    /// 实体抽象类
    /// </summary>
    /// <typeparam name="IdT"></typeparam>
    [Serializable]
    public abstract class Entity<IdT> : IEntity<IdT>
    {
        #region IEntity<IdT> 成员

        /// <summary>
        /// 获取 / 设置 主键
        /// </summary>
        public virtual IdT Id { get; set; }

        #endregion

        /// <summary>
        /// 判断两个对象是否相等
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return true;
            }

            Entity<IdT> entity = obj as Entity<IdT>;
            if (entity == null)
            {
                return false;
            }
            return this.Id.Equals(entity.Id);
        }

        /// <summary>
        /// 获取哈希值
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
    }
}
